package com.enqualcomm.kids.mvp.question;

import com.android.volley.VolleyError;
import com.enqualcomm.kids.mvp.NetworkModel;
import com.enqualcomm.kids.network.NetworkListener;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.CheckAiZhiShiVersionParams;
import com.enqualcomm.kids.network.socket.request.GetTerminalAskData;
import com.enqualcomm.kids.network.socket.request.SetAiZhiShiBlackboardDataParam;
import com.enqualcomm.kids.network.socket.response.AiZhiShiVersionResult;
import com.enqualcomm.kids.network.socket.response.BasicResult;
import com.enqualcomm.kids.network.socket.response.TerminalAskDataResult;

/**
 * Created by Sunzhigang on 2016/3/7.
 */
public class QusetionModel extends NetworkModel implements IChildQUestionModel{


    public void getAskData(String userid, String userkey, String terminalid, int type,NetworkListener<TerminalAskDataResult> listener) {
        GetTerminalAskData params = new GetTerminalAskData(userid,userkey,terminalid,type);
        loadDataFromServer(new SocketRequest<TerminalAskDataResult>(params,listener));
    }


    @Override
    public void getAskData(String userid, String userkey, String terminalid, int type, final IQusetionHandler handler) {
        GetTerminalAskData params = new GetTerminalAskData(userid,userkey,terminalid,type);
        loadDataFromServer(new SocketRequest<TerminalAskDataResult>(params, new NetworkListener<TerminalAskDataResult>() {
            @Override
            public void onError(VolleyError error) {
//                MyLogger.kLog().i(error);
                handler.onNetworkError();
            }
            @Override
            public void onSuccess(TerminalAskDataResult response) {
                if (response.code==0){
//                    MyLogger.kLog().i(response);
                    handler.getTerminalDataSuccess(response);
                }
            }
        }));
    }

    @Override
    public void getQuestionVersion(String userid, String userkey, final IQusetionHandler handler) {
        CheckAiZhiShiVersionParams params = new CheckAiZhiShiVersionParams(userid,userkey);
        loadDataFromServer(new SocketRequest<AiZhiShiVersionResult>(params, new NetworkListener<AiZhiShiVersionResult>() {
            @Override
            public void onError(VolleyError error) {
//                MyLogger.kLog().i(error);
            }

            @Override
            public void onSuccess(AiZhiShiVersionResult response) {
                if (response.code == 0){
//                    MyLogger.kLog().i(response);
                    handler.checkVersionSuccess(response);
                }
            }
        }));
    }

    @Override
    public void setAiZhiShiBlackboardData(String userid, String userkey, String terminalid, int type, int currentnum, String reward, final IQusetionHandler handler) {
        SetAiZhiShiBlackboardDataParam param = new SetAiZhiShiBlackboardDataParam(userid,userkey,terminalid,type,currentnum,reward);
        loadDataFromServer(new SocketRequest<BasicResult>(param, new NetworkListener<BasicResult>() {
            @Override
            public void onError(VolleyError error) {
//                MyLogger.kLog().i(error);
                handler.onNetworkError();
            }

            @Override
            public void onSuccess(BasicResult response) {
                if (response.code ==0){
//                    MyLogger.kLog().i(response);
                    handler.setAIZhiShiBlackboardDataSuccess();
                }
            }
        }));
    }
}
